<script>
let str = 'asdaasefasdfaxffsad'
function foo(str){
    if(str.length < 2){
        return str.length
    }
    let result = 0
    let maxstr = ''
    let len = str.length
    //记录当前出现的字符串
    let mapping = {}
    
    let i = 0,
        j = 0
    while(true){
        //j右移
        while(j < len && !mapping[str[j]]){
            mapping[str[j]] = true
            j++
        }
        //选出当前最大值
        if(j-i > result){
            maxstr = str.slice(i, j)
            result = j - i
        }
        if(j >= len){
            break
        }
        //i右移
        while(str[i] != str[j]){
            mapping[str[i]] = false
            i++
        } 

        i++
        j++
    }
    return [result, maxstr]
}
let a = foo(str)
console.log(a)
</script>